#include "boinc_db.h"
#include "backend_lib.h"
#include "util.h"
#include "sched_util.h"
#include "error_numbers.h"


int main() {
    DB_APP app;
    DB_WORKUNIT wu;
    char* wu_template;
    const char* infiles[] = {"infile"};
    char path[1024];

    SCHED_CONFIG config;
    config.parse_file();

    boinc_db.open(config.db_name, config.db_host, config.db_user, config.db_passwd);
    app.lookup("where name='justprint'");

    // write input file in the download directory
    //
    config.download_path("infile", path);  // remember: filenames need to be unique!!
    FILE* f = fopen(path, "w");
    fprintf(f,"random stuff\n");    
    fclose(f);

    read_file_malloc("templates/justprint_single_in.xml", wu_template);
    wu.clear();     // zeroes all fields
    strcpy(wu.name, "test_name_UNIQUE"); // workunit names need to be unique, too!
    wu.appid = app.id;
    wu.min_quorum = 2;
    wu.target_nresults = 2;
    wu.max_error_results = 5;
    wu.max_total_results = 5;
    wu.max_success_results = 5;
    wu.rsc_fpops_est = 1e10;
    wu.rsc_fpops_bound = 1e11;
    wu.rsc_memory_bound = 1e8;
    wu.rsc_disk_bound = 1e8;
    wu.delay_bound = 7*86400;
    create_work(
        wu,
        wu_template,
        "templates/justprint_out.xml",
        "templates/justprint_out.xml",
        infiles,
        1,
        config
    );
}
